<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * Item Set for KISON
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;kison/item-set&quot;, function (S, Base) {
<span id='KISSY-Kison-ItemSet'>    /**
</span>     * ItemSet for grammar
     * @class KISSY.Kison.ItemSet
     */
    return Base.extend({
        // Insert item by order
        addItem: function (item) {
            var items = this.get(&quot;items&quot;);
            for (var i = 0; i &lt; items.length; i++) {
                if (items[i].get(&quot;production&quot;).toString() &gt; item.get(&quot;production&quot;).toString()) {
                    break;
                }
            }
            items.splice(i, 0, item);
        },

        size: function () {
            return this.get(&quot;items&quot;).length;
        },

        findItemIndex: function (item, ignoreLookAhead) {
            var oneItems = this.get(&quot;items&quot;);
            for (var i = 0; i &lt; oneItems.length; i++) {
                if (oneItems[i].equals(item, ignoreLookAhead)) {
                    return i;
                }
            }
            return -1;
        },

        getItemAt: function (index) {
            return this.get(&quot;items&quot;)[index];
        },

        equals: function (other, ignoreLookAhead) {
            var oneItems = this.get(&quot;items&quot;),
                i,
                otherItems = other.get(&quot;items&quot;);
            if (oneItems.length != otherItems.length) {
                return false;
            }
            for (i = 0; i &lt; oneItems.length; i++) {
                if (!oneItems[i].equals(otherItems[i], ignoreLookAhead)) {
                    return false;
                }
            }
            return true;
        },
        toString: function (withGoto) {
            var ret = [],
                gotos = this.get('gotos');
            S.each(this.get(&quot;items&quot;), function (item) {
                ret.push(item.toString());
            });
            if (withGoto) {
                ret.push('start gotos:');
                S.each(gotos, function (itemSet, symbol) {
                    ret.push(symbol + ' -&gt; ');
                    ret.push(itemSet.toString())
                });
                ret.push('end gotos:');
            }
            return ret.join(&quot;\n&quot;);
        },

        addReverseGoto: function (symbol, item) {
            var reverseGotos = this.get(&quot;reverseGotos&quot;);
            reverseGotos[symbol] = reverseGotos[symbol] || [];
            reverseGotos[symbol].push(item);
        }
    }, {
        ATTRS: {
            items: {
                value: []
            },
            gotos: {
                value: {}
            },
            reverseGotos: {
                // 多个来源同一个symbol指向自己
                //{ c: [x,y]}
                value: {}
            }
        }
    });
}, {
    requires: ['base']
});</pre>
</body>
</html>
